<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 3、求Sn=a+aa+aaa+……+aa……a之值,其中a、n是文本框输入的两个数字。 -->
    请输入a:
    <input id="a" type="text">
    请输入n:
    <input id="n" type="text">
    <input type="button" value="=" onclick="calc()">
    <input id="result" type="text">
    <script>
        function calc() {
            var a = parseFloat(document.getElementById("a").value);
            var n = parseFloat(document.getElementById("n").value);
            var sum = a;
            var add = a;
            for (var i = 1; i < n; i++) {
                // var add = 0;
                // for (var j = 0; j < i - 1; j++) {
                //     add = add + a * Math.pow(10, j);
                // }
                add = add * 10 + a;
                sum += add;
            }
            document.getElementById("result").value = sum;
        }
    </script>
</body>

</html>